/*
 * Copyright (c) 2017, AEye
 * All rights reserved.
 */

#include "PcapPacket.hpp"

#include <utility>

namespace aeye {

PcapPacket::PcapPacket(uint32_t srcAddr, std::string srcIpAddress, uint16_t srcPort, const uint8_t *data, size_t size) :
source_ip_address_(std::move(srcIpAddress)),
source_port_(srcPort) {
  (void) srcAddr;
  if (data) {
    data_ = std::vector<uint8_t>(data, data + size); // Fair notice. Here we do memory copy implicitly via vector's constructor
  }
}

const std::string &PcapPacket::sourceIpAddress() const noexcept {
  return source_ip_address_;
}

uint16_t PcapPacket::sourcePort() const noexcept {
  return source_port_;
}

const uint8_t* PcapPacket::data() const noexcept {
  return data_.data();
}

std::vector<uint8_t>& PcapPacket::getData() noexcept {
  return data_;
}

size_t PcapPacket::size() const noexcept {
  return data_.size();
}

} // end namespace aeye
